<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='./vue.js'></script>
</head>

<body>
    <div id='app'>
        <h1>app 组件 --- {{ msg }} </h1>

        <father :msg="msg"></father>
    </div>
</body>
<script>

    const son = {
        template: `
            <div>
                <h1> 子组件 ---- {{ msg }} -- {{name}} </h1>    
            </div>
        `,
        props: {
            msg: String
        },
        // inject 将祖先组件发射的数据，注入到当前组件中(接收)
        inject: ['name']
    }

    const father = {
        template: `
            <div>
                <h1> 父组件 ---- {{ msg }} -- {{ name }} </h1>    
                <son :msg='msg'></son>
            </div>
        `,
        props: ['msg'],
        inject: ['name'],
        components: {
            son
        }
    }

    const app = {
        data() {
            return {
                msg: '传家宝',
                name: '二手玫瑰'
            }
        },
        // 配置提供 依赖（发射值）
        provide() {
            return {
                // return 出去的内容就是要共享的内容
                name: this.name
            }
        },
        methods: {},
        components: {
            father
        }
    }
    const vm = Vue.createApp(app).mount('#app')
</script>

</html>